<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,body{
            margin: 0;
        }
        .nav{
            position: relative;
            width:100%;
            height: 10vw;
            font-size: 5vw;
            line-height: 10vw;
            color: white;
            text-align: center;
        }

        .red{
           background-color: red;
        }

        .blue{
           background-color: blue;
        }

        .yellow{
           background-color: yellow;
        }

        .green{
           background-color: green;
        }


    </style>


<script>
    let targetNav;
    window.onload




    // 检测当前容器滚动的高度
    window.onscroll=function(){
        let scrollTop=document.querySelector("body").scrollTop;
        let viewHeight=document.body.clientHeight;      //当前视图的高度
        let scrollHeight=document.querySelector("body").scrollHeight


        console.log(scrollTop,scrollHeight,viewHeight)
    }
</script>
</head>
<body>
    <div class="nav blue">
        <div style="width: 80vw;height: 1vw;position:absolute;left:50%;top:50%;translate:(50%,50%)">
            <div style="width: 30%;height: 100%;position: absolute;left:0;topbackground-color: yellow;"></div>
        </div>
    </div>
    <div class="nav red">
       2
    </div>
    <div class="nav green">
        3
    </div>
    <div class="nav yellow">
        4
    </div>

    <div style="width:100%;height: 200px;"></div>

    
</body>
</html>